from common.base_page import BasePage

from appium.webdriver.common.appiumby import AppiumBy
from time import sleep


class PostingPage(BasePage):
    '''点击发现'''
    btn_desktop_discovery1 = (AppiumBy.ID, 'com.jhss.youguu:id/btn_desktop_discovery')
    '''点击置灰头像'''
    head_pic1 = (AppiumBy.ID, 'com.jhss.youguu:id/head_pic')
    '''发布前的帖子数量'''
    tv_weibo_num1 = (AppiumBy.ID, 'com.jhss.youguu:id/tv_weibo_num')
    '''点击返回按钮'''
    btn_back = (AppiumBy.ID, 'com.jhss.youguu:id/btn_back')
    '''点击聊股'''
    btn_desktop_talk = (AppiumBy.ID, 'com.jhss.youguu:id/btn_desktop_talk')
    '''点击铅笔按钮'''
    iv_public_twitter = (AppiumBy.ID, 'com.jhss.youguu:id/iv_public_twitter')
    ''''点击优顾大家谈'''    '''53,898'''
    bar_name = (AppiumBy.ID, 'com.jhss.youguu:id/bar_name')
    '''输入标题'''
    title_content = (AppiumBy.ID, 'com.jhss.youguu:id/title_content')
    '''输入正文'''
    edit_content = (AppiumBy.ID, 'com.jhss.youguu:id/edit_content')
    '''点击发布'''
    title_right_button = (AppiumBy.ID, 'com.jhss.youguu:id/title_right_button')
    ''''点击发现'''
    btn_desktop_discovery = (AppiumBy.ID, 'com.jhss.youguu:id/btn_desktop_discovery')
    ''''点击置灰头像'''
    head_pic = (AppiumBy.ID, 'com.jhss.youguu:id/head_pic')
    '''帖子发布数-用于断言'''
    tv_weibo_num = (AppiumBy.ID, 'com.jhss.youguu:id/tv_weibo_num')
    '''正文内容-用于断言'''
    contentView = (AppiumBy.ID, 'com.jhss.youguu:id/contentView')
    '''断言昵称'''
    TextView = AppiumBy.ID, 'com.jhss.youguu:id/tv_nick_name'

    # 发布之前的帖子数量
    def before(self):
        '''点击返回按钮'''
        '''点击发现'''
        self.click_ele(self.btn_desktop_discovery)
        sleep(2)
        '''点击置灰头像'''
        self.click_ele(self.head_pic1)
        sleep(2)

    def posting(self, title, connect):
        '''点击返回按钮'''
        self.click_ele(self.btn_back)
        sleep(3)

        ''''点击聊股'''
        self.click_ele(self.btn_desktop_talk)
        '''点击铅笔'''
        self.click_ele(self.iv_public_twitter)
        '''点击优顾大家谈'''
        self.tap(53, 898)
        '''输入标题'''
        self.send_keys(self.title_content, title)
        sleep(2)
        '''输入正文'''
        self.send_keys(self.edit_content, connect)
        sleep(2)
        '''点击发布'''
        self.click_ele(self.title_right_button)
        sleep(2)
        # 刷新
        self.swip_down(2)
        sleep(4)
        '''点击发现'''
        self.click_ele(self.btn_desktop_discovery)
        sleep(2)
        '''点击头像'''
        self.click_ele(self.head_pic)
        sleep(2)
        '''发布帖子数+1'''
        self.find_element(self.tv_weibo_num)
        sleep(2)

